<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")
	{
				
				$taxtcountry = mysql_real_escape_string($_REQUEST['title']);
				$taxtisocode2 = mysql_real_escape_string($_REQUEST['desc']);
				$taxtisocode3 = mysql_real_escape_string($_REQUEST['meta']);
				
				
				$insert = "INSERT INTO `tblpage`
				(`vartitle` ,`txtdesc`, `varmeta`)
				VALUES ('$taxtcountry', '$taxtisocode2', '$taxtisocode3')";
				
				$sql=$obj_db->insert($insert);
				
				header("location:page.php?msg=add");
				die();
	}	
		

// UPDATE the record
$txtcountry1 = "";
$txtisocode21 = "";
$txtisocode31 = "";

$action=1;

if((isset($_REQUEST['a']) && trim($_REQUEST['a'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")))
{
 	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'])!="")
 	{
		$screen_id =  $_REQUEST['intid'];
		$sql = "select * from tblpage where intid ='$screen_id'";
		$result = $obj_db->select($sql);
		
		if(count($result)<=0)
		{
			echo " No Record Found!<br>";
			die();
		}
		
		if($result)
		{
			foreach($result as $row)
			{
				$txtcountry1 = stripslashes($row['vartitle']);	   
		   		$txtisocode21 = stripslashes($row['txtdesc']);
				$txtisocode31 = stripslashes($row['varmeta']);
				$action=2;
			}
		}
		
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update")
		{
			
				$taxtcountry = mysql_real_escape_string($_REQUEST['title']);
				$taxtisocode2 = mysql_real_escape_string($_REQUEST['desc']);
				$taxtisocode3 = mysql_real_escape_string($_REQUEST['meta']);
			
			$sql_upd ="UPDATE tblpage SET  
						`vartitle` = '$taxtcountry',
						`txtdesc` = '$taxtisocode2',						 
						`varmeta` = '$taxtisocode3'
						where intid ='$screen_id'";
						 
		//echo $sql_upd;
			//die();
			
			$result = $obj_db->edit($sql_upd);
			$action=1;
			
			header("location:page.php?msg=edit");
			die();
		}
	}

}

//DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{	
		$id =  $_REQUEST['intid'];
		$sql= "DELETE FROM `tblpage` WHERE `intid` ='$id'";
		$query1 = mysql_query($sql);
		
		header("location:page.php?msg=del");
		die();
	}
}


?>
<?php include("inc/header.php");?>
<script type="text/javascript" src="js/tiny_mce.js"></script>
<script language="javascript" src="js/currency.js"></script>
<script type="text/javascript">
	// O2k7 skin (silver)
	tinyMCE.init({
		// General options
		mode : "exact",
		elements : "desc",
		theme : "advanced",
		skin : "o2k7",
		skin_variant : "black",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_resizing : false
	});
</script>
<body>

<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="95%"><?php   
   if(isset($_REQUEST['script']))
	{
	if(trim($_REQUEST['script'])=='addpage' || trim($_REQUEST['script'])=='editpage')
	{
	?>
		<form action="" method="post" enctype="multipart/form-data" name="currency">
	
      <table width="60%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
        <tr class="bg1">
          <td colspan="5" align="center"><strong>
            <?php if($_REQUEST['script']=='addpage'){echo "Add New Page...";}
	if($_REQUEST['script']=='editpage'){echo "Edit Page...";}?>
          </strong></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left">&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right">(* All fields are Required)</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="2%">&nbsp;</td>
          <td width="30%" align="left" class="sltimg">*Page Title </td>
          <td width="3%">:</td>
          <td width="56%" align="left"><label>
            <input name="title" type="text" id="title" value="<?php echo $txtcountry1;?>" />
          </label></td>
          <td width="9%">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left" valign="top" class="sltimg">*Description </td>
          <td valign="top">:</td>
          <td align="left"><textarea name="desc" rows="40" id="desc"><?php echo $txtisocode21;?></textarea></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left" class="sltimg">*Meta </td>
          <td>:</td>
          <td align="left"><input name="meta" type="text" id="meta" value="<?php echo $txtisocode31;?>" /></td>
          <td>&nbsp;</td>
        </tr>

        <tr>
          <td colspan="5" align="left">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="<?php echo ($action==2) ? "Update":"Submit"; ?>" onClick="return check();"/></td>
        </tr>
        <tr>
          <td colspan="5" align="center">&nbsp;</td>
        </tr>
      </table>
    <?php
	}
}
else
{
?>
<br />
		<br />
		<table width="70%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
          <tr class="bg1">
            <td colspan="4"align="left"><strong >Page  List... </strong>&nbsp;&nbsp;<a href="currency.php?script=addcurrency" class="aa"></a><a href="currency.php?script=addcurrency" class="aa"></a></td>
            <td align="center"><a href="page.php?script=addpage" class="aa">[NEW]</a></td>
          </tr>
          <tr align="center" class="tblbg3">
            <td class="tblbg3">Title</td>
            <td class="tblbg3">Description</td>
            <td class="tblbg3">Meta</td>
			
			<td class="tblbg3">Edit</td>
            <td>Delete</td>
          </tr>
          <?php
	  
	  
	  
	  
		?>
          <?php
   		$sql="select * from tblpage";
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{
            $id=$result[$i]['intid'];
			//$imagepath = "../images/manuf/";
			//$limit=$result[$i]['varimagepath'];
			//$imagename = $imagepath.$limit;
			?>
          <tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onMouseOut="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
            <td align="center"><?php echo $result[$i]['vartitle'];?></td>
            <td align="center"><?php echo $result[$i]['txtdesc'];?></td>
            <td align="center"><?php echo $result[$i]['varmeta'];?></td>
			
			<td align="center"><a class="link" Title="Click here to Edit" href="page.php?script=editpage&amp;a=2&amp;intid=<?php echo $result[$i]['intid']; ?>"><img src="images/edit.bmp" border="0"/></a></td>
            <td align="center"><a Title="Click here to Delete" href="page.php?a=3&amp;intid=<?php echo $result[$i]['intid']; ?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
          </tr>
          <?php }}?>
          <tr>
            <td colspan="7" align="center">&nbsp;</td>
          </tr>
        </table>
		<?php }?>
        </form>	</td>
    <td width="3%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><?php include("inc/bottom.php");?></td>
  </tr>
</table>


